<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0" />
    <title>沃闪购</title>
    <link rel="icon" href="../img/bitbug_favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/normalize.css" />
    <!--<link rel="stylesheet" href="index.css"/>-->
    <!--<link rel="stylesheet" href="../index.css"/>-->
    <link rel="stylesheet" href="../index_format.css" />
    <link rel="stylesheet" href="../css/layer.css" />

    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/rem.js"></script>
    <script type="text/javascript" src="../js/tool.js"></script>
    <script type="text/javascript" src="../js/clipboard.min.js"></script>
    <script src="../js/iscroll.js"></script>
    <script type="text/javascript">
        var myScroll;

        function loaded() {
            myScroll = new IScroll('#wrapper', {
                bounce: false,
                bounceEasing: 'elastic',
                bounceTime: 200
            });

            myScroll.on('scrollStart', scrollF);
        }

        function scrollF() {
            console.log('hide');
            var height_ul = $('.product-list').height();
            var height_btn = $('.front-next').height();
            var scrolH = height_ul + height_btn;
            console.log(scrolH);
            $('.btn-group').insertBefore('.order-link');
            $('.wo-topic').hide(500)
            $('.container').css({
                height: "85%"
            });
            $('#wrapper').css({
                height: "6.4rem"
            })
        }

        function scrollEndF() {
            console.log('show');
            // $('.header').show()
            $('.wo-topic').show(500)
            $('.container').css({
                height: "75%"
            });
            $('#wrapper').css({
                height: "3.2rem"
            })
        }
        document.addEventListener('touchmove', function(e) {
            e.preventDefault();
        }, false);
    </script>
</head>

<body>
    <div class="header ">
        <div><img src="../img/wo-logo.png" alt="" /></div>

    </div>
    <div class="container n-bor c-container">
        <div class="flex-box">
            <div class="choose-info">
                <div class="cash-info">
                    <ul>
                        <li>您的可提现佣金金额：<i id="cash_total"></i>元</li>
                        <li>请输入提现金额：<input type="number" id="drawCash">元</li>
                        <li>*每月提现金额最低50元，最高800元*</li>
                        <li><a href="#" id="check_drawcash">确认提现</a></li>
                    </ul>
                </div>
                <p class="list-name"><span>提现明细</span></p>
                <div class="cash-container">
                    <div class="cash-list">
                        <ul>
                            <li>
                                <span>提现单号：</span><span></span>
                            </li>
                            <li><span>提现金额：</span><span></span></li>
                            <li><span>提现时间：</span><span></span></li>
                            <li><span>提现状态：</span><span></span></li>
                        </ul>
                        <ul>
                            <li>
                                <span>提现单号：</span><span></span>
                            </li>
                            <li><span>提现金额：</span><span></span></li>
                            <li><span>提现时间：</span><span></span></li>
                            <li><span>提现状态：</span><span></span></li>
                        </ul>
                    </div>
                    <div class="front-next" data-total=""><a href="#" id="turn_page_fr" class="page" data-index="0">上一页</a><a href="#" id="turn_page_th" class="page" data-index="2">下一页</a>
                        <!-- <div id="scroller">

                        <div class="front-next" data-total=""><a href="#" id="turn_page_fr" class="page" data-index="0">上一页</a><a href="#" id="turn_page_th" class="page" data-index="2">下一页</a>
                        </div>
                    </div> -->
                    </div>

                </div>
            </div>
        </div>
        <script>
            // $('header').on('touchstart', function(event) {
            //     event.preventDefault();
            //     event.stopPropagation();
            //     return false;
            // })
            // $('.product-container').on('touchmove', function() {
            //     return true;
            // })
        </script>
        <script type="text/javascript" src="../js/layer.js"></script>

        <script>
            function getTime(seconds) {
                //                seconds.toString();
                var arr = seconds;
                console.log(arr)
                var date = new Date(arr);
                console.log(date)
                var month = date.getMonth();
                var hour = date.getHours();
                var minutes = date.getMinutes();
                var seconds = date.getSeconds();
                month += 1;
                //                date.setTime(seconds);
                date.getFullYear();
                date.getDate();
                if (hour < 10) {
                    hour = "0" + hour
                }
                if (minutes < 10) {
                    minutes = "0" + minutes
                }
                if (seconds < 10) {
                    seconds = "0" + seconds
                }

                console.log(date.getFullYear() + '年' + month + '月' + date.getDate() + '日 ' + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
                return date.getFullYear() + '年' + month + '月' + date.getDate() + '日 ' + hour + ":" + minutes + ":" + seconds;
            }

            function getStatus(status) {
                switch (status) {
                    case '0':
                        return "完成";
                    case '1':
                        return "未完成";
                }
            }
            var bes_poster = {
                user_info: '.user-info',
                user_img: "#user_img",
                user_id: '#user_id',
                cash_total: '#cash_total',
                drawCash: '#drawCash',
                user_state: '#user_state',
                user_channel: '#user_channel',
                refresh: "#refresh",
                check_drawcash: '#check_drawcash',
                turn_page_fr: '#turn_page_fr',
                turn_page_th: '#turn_page_th',
                count: 0,
                host_server: getServerHost(),
                get_cash_url: '../json/cash.json',
                draw_cash_url: '../json/draw_cash.json',
                info_url: '/api/shopping/userInfo?',
                order_url: '/api/shopping/queryOrderList',
                front_next: '.front-next',
                need_name: ".need_name_fr",
                need_time: '.need_time_fr',
                need_status: '.need_status_fr',
                order_status_ok: "已完成",
                order_status_no: "未完成",
                cash_list: '.cash-list',
                btn_group: '.btn-group',
                btnCopy: '.btnCopy',
                drawCash: '#drawCash',
                product_status: ["", "待支付", "已取消", "支付成功", "已发货", "已确认收货", "订单完成", "申请退款", "已退款",
                    "等待开卡写卡", "等待外呼", "外呼完成", "物流发货", "活体认证", "激活完成", "订单中心处理", "订单中心已撤单"
                ],
                init: function() {

                    this.getInfo();
                    this.getCash();
                    this.btnclick();
                    this.copyUrl();

                },
                copyUrl: function() {
                    var context = this;
                    $(context.btnCopy).click(function() {
                        location.href = "http://o2o2.unisk.cn:8081/console/system/toLogin.do"
                    })
                },
                userInfo: function(id, name, status) {
                    var context = this;
                    //console.log(id, name, status)
                    if (id) {
                        $(context.user_img).attr('src', "../img/user.png");
                        $(context.user_id).html(id);
                        $(context.user_id).attr("data-id", id);
                        if ('1' == status) {
                            $(context.user_state).attr('class', 'red-info').html('未审核');
                            $(context.btn_group + " a:first-child").attr('href', '#').attr("class", "btn-style btn-false");
                        } else if ('2' == status) {
                            $(context.user_state).attr('class', 'green-info').html('已通过');
                            $(context.btn_group + " a:first-child").attr('href', './mycode.html').attr("class", "btn-style btn-ok");
                        } else if ('3' == status) {
                            $(context.user_state).attr('class', 'red-info').html('已冻结');
                            $(context.btn_group + " a:first-child").attr('href', './mycode.html').attr("class", "btn-style btn-false");
                        } else {
                            console.log(status)
                        }
                        $(context.user_channel).html(name);
                    } else {
                        console.log('no get info')
                    }
                },
                //提现
                getCash: function() {
                    var context = this;
                    $(context.check_drawcash).click(function(e) {
                        e.preventDefault();
                        // todo:判断提现金额是否高于佣金
                        var monney = $(context.drawCash).val();
                        var cash_total = $(context.cash_total).text();

                        function CheckRange(monney) {
                            if (isNaN(monney)) {
                                layer_msg("输入数据为数字！");
                                return false;
                            }
                            if (Number(monney) < 50 || Number(monney) > 800) {
                                layer_msg("可提的金额在50到800元");
                                return false;
                            }
                            return true;
                        }

                        function CheckTotal(cash_total) {
                            if (isNaN(monney)) {
                                layer_msg("error");
                                return false;
                            } else if (Number(cash_total) == 0) {
                                layer_msg("您暂时无佣金");
                                return false;
                            }
                            return true;
                        }
                        if (!CheckTotal(cash_total)) {
                            return;
                        }
                        if (!CheckRange(monney)) {
                            return;

                        }
                        $.ajax({
                            type: 'POST',
                            // url: context.host_server + context.draw_cash_url,
                            url: context.draw_cash_url,
                            data: {
                                "userId": sessionStorage.getItem('userId'),
                                "num": monney
                            },
                            success: function(response) {
                                var res = response.res;
                                if ('200' == response.code) {
                                    layer_msg('恭喜您已提现成功');
                                    $(context.drawCash).val('')
                                    context.getInfo();
                                } else {
                                    layer_msg('信息加载失败，请重试')
                                }
                                //                            context.showNeeds(context.count, response);
                            },
                            error: function() {
                                layer_msg(' 返回数据出现异常');
                            }
                        });
                    })
                },
                //获取个人信息
                getInfo: function() {
                    var context = this;
                    var data = JSON.parse(sessionStorage.getItem('res'));
                    console.log(data);
                    var timer = setTimeout(function() {
                        $.ajax({
                            type: 'GET',
                            url: context.host_server + context.info_url,
                            data: "userId=" + data.userId,
                            success: function(response) {
                                var res = response.res;
                                if ('200' == response.code) {
                                    clearTimeout(timer);
                                    timer = null;
                                    context.userInfo(res.account_no, res.channel_name, res.status);
                                    context.getNeeds(1, res);

                                } else {
                                    layer_msg('信息加载失败，请重试')
                                }

                                //                            context.showNeeds(context.count, response);
                            },
                            error: function() {
                                layer_msg(' 返回数据出现异常');
                            }
                        });
                        //                获取用户信息
                    }, 1000)


                },
                //获取商品信息
                getNeeds: function(pageNo, res) {
                    var context = this;
                    var orderList = {
                        accountNo: res,
                        pageNo: pageNo,
                        pageSize: 2
                    };

                    console.log(orderList);
                    $(context.front_next).css("display", "block");
                    $.ajax({
                        type: 'POST',
                        // url: context.host_server + context.get_cash_url,
                        url: '../json/cash.json',
                        data: JSON.stringify(orderList),
                        contentType: "application/json;charset=UTF-8",
                        dataType: "json",
                        success: function(response) {
                            if ('200' == response.code) {
                                var res = response.res;
                                console.log(response.res.dc_list.length);
                                if (res.dc_list.length) {
                                    context.showNeeds(pageNo, res);
                                } else if ('888' == response.code) {
                                    layer_msg(response.msg)
                                } else if ('990' == response.code) {
                                    layer.open({
                                        content: "提现信息为空",
                                        btn: '确定'
                                    });
                                    $(context.cash_list).html('<p style="text-align: center;margin-top: .9rem">提现信息为空</p>')
                                    $(context.front_next).css("display", "none");
                                }
                            } else {
                                layer_msg(response.msg)
                            }
                        },
                        error: function() {
                            layer_msg('返回数据出现异常');
                        }

                    })
                },
                //添加订单数据到列表
                showNeeds: function(index, response) {
                    var context = this;
                    //格式化时间
                    console.log(response);
                    $(context.front_next).attr('data-total', response.totalPage);
                    $(context.cash_total).text(response.total)
                    response = response.dc_list;
                    swapPage(index, response);
                    //翻页
                    function swapPage(index, response) {
                        var ul = '';
                        var len = response.length;
                        //订单状态判断
                        if (!len) {
                            alert('当前用户提现为空');
                            return;
                        }
                        var order_status = {};

                        console.log('-------------------------------------')
                        for (var i = 0; i < len; i++) {
                            // var page = Number(index) + Number(i);
                            console.log(response[i]);
                            var res = response[i];
                            // var index = response[i].status;
                            ul +=
                                `    <ul>
                                    <li>
                                        <span>提现单号：</span><span>${res.dc_id}</span>
                                    </li>
                                    <li><span>提现金额：</span><span>${res.dc_monney}元</span></li>
                                    <li><span>提现时间：</span><span>${getTime(Number(res.dc_time))}</span></li>
                                    <li><span>提现状态：</span><span>${getStatus(res.dc_status)}</span></li>
                                </ul>`;
                        }
                        console.log(ul);
                        $(context.cash_list).html(ul);
                    }
                },
                btnclick: function() {
                    //            点击左边
                    var context = this;

                    $(context.turn_page_fr).click(function(e) {
                        e.preventDefault();
                        // myScroll.scrollTo(0, 0, 300, 0);
                        var index_fr = Number($(context.turn_page_fr).attr('data-index'));
                        var index_th = Number($(context.turn_page_th).attr('data-index'));
                        var res = JSON.parse(sessionStorage.getItem('res'));
                        if (!Number($(context.turn_page_fr).attr('data-index'))) {
                            layer_msg('没有上一页了')
                        } else {
                            context.getNeeds(index_fr, res);
                            $(context.turn_page_fr).attr('data-index', index_fr - 1);
                            $(context.turn_page_th).attr('data-index', index_th - 1);
                        }
                    })
                    //点击右边
                    $(context.turn_page_th).click(function(e) {
                        // e.preventDefault();

                        // myScroll.scrollTo(0, 0, 1000, 0)
                        e.preventDefault();
                        var index_fr = Number($(context.turn_page_fr).attr('data-index'));
                        var index_th = Number($(context.turn_page_th).attr('data-index'));
                        //            todo    返给我总共的数据条数
                        var res = JSON.parse(sessionStorage.getItem('res'));
                        var next = $(context.turn_page_th).attr('data-index');
                        var total = $(context.front_next).attr('data-total');
                        console.log(total - (next - 1) * 5);
                        if ((total - (next - 1) * 5) > 0) {
                            context.getNeeds(index_th, res);
                            $(context.turn_page_fr).attr('data-index', index_fr + 1);
                            $(context.turn_page_th).attr('data-index', index_th + 1)
                        } else {
                            layer_msg('没有下一页了')
                        }
                    })
                }

            }
            bes_poster.init();
        </script>
</body>

</html>
